#!/bin/sh
rm -f config.h

cat > config.h << EOM

/* I_MALLOC:
 * This symbol, if defined, indicates to the C program that it should
 * include <malloc.h>.
 */
EOM
if test -f /usr/include/malloc.h > /dev/null; then
   echo '#define I_MALLOC     /**/' >> config.h
else
   echo '/*#define I_MALLOC     /**/' >> config.h
fi

cat >> config.h << EOM

/* I_STDLIB:
 * This symbol, if defined, indicates that <stdlib.h> exists and should
 * be included.
 */
EOM
if test -f /usr/include/stdlib.h > /dev/null; then
   echo '#define I_STDLIB     /**/' >> config.h
else
   echo '/*#define I_STDLIB     /**/' >> config.h
fi

cat >> config.h << EOM

/* I_MACHINE_PTE:
 * This symbol is defined if sys/param.h includes machine/pte.h.
 */
EOM
if grep 'machine/param.h' /usr/include/sys/param.h >/dev/null 2>&1 ; then
   if grep 'machine/pte;' /usr/include/machine/param.h >/dev/null 2>&1 ; then
      echo '#define I_MACHINE_PTE     /**/' >> config.h
   else
      echo '/*#define I_MACHINE_PTE     /**/' >> config.h
   fi
else
   echo '/*#define I_MACHINE_PTE     /**/' >> config.h
fi

cat >> config.h << EOM

/* I_SYS_VM:
 * This symbol, if defined, indicates to the C program that it should
 * include <sys/vm.h>.
 */
EOM
if test -f /usr/include/sys/vm.h > /dev/null; then
   echo '#define I_SYS_VM     /**/' >> config.h
else
   echo '/*#define I_SYS_VM     /**/' >> config.h
fi

cat >> config.h << EOM

/* BSD44:
 * This symbol is defined if net/route.h uses radix nodes.
 */
/* RT_TABLES:
 * This symbol is defined if net/route.h has rt_tables.
 */
EOM
if grep 'radix_node_head' /usr/include/net/route.h >/dev/null 2>&1 ; then
   echo '#define BSD44     /**/' >> config.h
   if grep 'rt_tables' /usr/include/net/route.h >/dev/null 2>&1 ; then
      echo '#define RT_TABLES     /**/' >> config.h
   else
      echo '/*#define RT_TABLES     /**/' >> config.h
   fi
else
   echo '/*#define BSD44     /**/' >> config.h
   echo '/*#define RT_TABLES     /**/' >> config.h
fi

cat >> config.h << EOM

/* VMUNIX:
 * This symbol contains the full pathname of the kernel
 */
EOM
if test -f /vmunix; then
# SunOS, Ultrix, OSF/1
   dflt=/vmunix
elif test -f /kernel; then
# FreeBSD
   dflt=/kernel
elif test -f /bsd; then
# BSDI
   dflt=/bsd
elif test -r /hp-ux; then
# HP-UX
   dflt=/hp-ux
elif $test -r /irix; then
# IRIX
   dflt=/irix
elif $test -r /xenix; then
   dflt=/xenix
elif $test -r /mach; then
   dflt=/mach
elif $test -r /dgux; then
   dflt=/dgux
elif $test -r /unix; then
   dflt=/unix
elif $test -r /syst; then
   dflt=/syst
elif $test -r /arix; then
   dflt=/arix
else
   dflt='unknown'
   set X /*x
   shift
   case $# in
   1)
      if $test -r "$1"; then
         dflt="$1"
      fi
      ;;
   esac
fi

: first determine how to suppress newline on echo command
(echo "hi there\c" ; echo " ") >.echotmp
if grep c .echotmp >/dev/null 2>&1 ; then
   n='-n'
   c=''
else
   n=''
   c='\c'
fi
rm -f .echotmp

echo $n "What is the name of your kernel [$dflt]? $c"
read ans
if test "$ans" = "" ; then
   ans=$dflt
fi
echo '#define VMUNIX' \"$ans\" >> config.h

cat >> config.h << EOM

/* MYUNAME:
 * System description
 */
EOM
myuname=`( (uname -a) 2>/dev/null || hostname) 2>&1`
myuname=`echo $myuname | sed -e 's/^[^=]*=//' | tr '\012' ' '`
echo '#define MYUNAME' \"$myuname\" >> config.h
